//
//  JYShopCartTableViewProxy.m
//  JYFarm
//
//  Created by 花花 on 2017/10/21.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYShopCartTableViewProxy.h"
#import "JYShopCell.h"
#import "JYShopModel.h"
@implementation JYShopCartTableViewProxy
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataArray.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    JYShopCell *cell = [tableView dequeueReusableCellWithIdentifier:@"JYShopCellID"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
 
    cell.model = [self.dataArray safeObjectAtIndex:indexPath.row];

    
    JYWeakSelf;
    cell.selectBtnClick = ^(BOOL isSelected){
        
        if (weakSelf.ShopCartHandlerSelectBlock) {
            weakSelf.ShopCartHandlerSelectBlock(isSelected,indexPath);
        }
        
    };
    cell.shopcartCountEditBlock = ^(NSInteger count){
        if (weakSelf.ShopCartHandlerChangeCountBlock) {
            weakSelf.ShopCartHandlerChangeCountBlock(count, indexPath);
        }
        
    };
    
    
    return cell;
    
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleDelete;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    for (UIView * sv in cell.subviews) {
        
        if ([sv isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")]) {
            
            if (self.ShopCartHandlerDeleteBlock) {
                
                self.ShopCartHandlerDeleteBlock(indexPath);
            }
        }
    }
}

@end
